setwd('C:/Users/luke_/Desktop/[Projects]NaoDao_ClosedBeta_1st/NaoDao_DATA/OfflineDATA/1_Code/pivot_longer')
library(tidyverse)
library(readxl)
library(rio)

AllInfo_MID_naodao_df = readxl::read_excel('AllInfo_MID_naodao_df.xlsx')
AllInfo_MID_offline_df = read_excel('AllInfo_MID_offline_df.xlsx')
AllInfo_MID_pav_df = read_excel('AllInfo_MID_pav_df.xlsx')
# mental_rotation_data = read_excel('mental_rotation_wide.xlsx')
# stroop_stats_data_wide = read_excel('stroop_stats_data_wide.xlsx')

#-------------------------------------------------------------------------------
AllInfo_MID_naodao_df_long = AllInfo_MID_naodao_df %>% 
  select(!c(1,3)) %>% 
  tidyr::pivot_longer(
    cols = !c(ID,approach),
    names_to = c('blocktype','tasktype','DVtype'),
    values_to = 'DepVar',
    names_pattern = '(.*)_(.*)_(.*)'
  )
# export data
rio::export(AllInfo_MID_naodao_df_long,'AllInfo_MID_naodao_df_long.xlsx')

#-------------------------------------------------------------------------------
AllInfo_MID_pav_df_long = AllInfo_MID_pav_df %>% 
  select(!c(1,3)) %>% 
  tidyr::pivot_longer(
    cols = !c(ID,approach),
    names_to = c('blocktype','tasktype','DVtype'),
    values_to = 'DepVar',
    names_pattern = '(.*)_(.*)_(.*)'
  )
# export data
rio::export(AllInfo_MID_pav_df_long,'AllInfo_MID_pav_df_long.xlsx')
#-------------------------------------------------------------------------------
AllInfo_MID_offline_df_long = AllInfo_MID_offline_df %>% 
  select(!c(1,3)) %>% 
  tidyr::pivot_longer(
    cols = !c(ID,approach),
    names_to = c('blocktype','tasktype','DVtype'),
    values_to = 'DepVar',
    names_pattern = '(.*)_(.*)_(.*)'
  )
# export data
rio::export(AllInfo_MID_offline_df_long,'AllInfo_MID_offline_df_long.xlsx')
